<div class="content-form edit-aluno">
    <?php echo $this->partial('aluno/menu.phtml', array('urlbase'=>$this->urlbase,'urlfoto'=>$this->urlfoto,'modulo'=>$this->modulo,'controller' => $this->controller, 'action' => $this->action, 'data' => $this->data)); ?>
    
    <div class="content-list row_bc">
        
        <h2><?php echo $this->Menualuno_nom[$this->action];?> - <?php echo $this->lista['PLS_NOM']; ?></h2>

        <?php if($this->op == 'list'){ ?>
        <div class="lista-questoes">
            <input type="hidden" id="ALU_ID" name="ALU_ID" value="<?php echo $this->data['ALU_ID']; ?>">
            <input type="hidden" id="PLS_ID" name="PLS_ID" value="<?php echo $this->pls_id; ?>">
            
            <?php
            
            $readonly = $this->lista['PLS_STA'] == 2 ? 'readonly="" disabled=""':'';
            
            $query = 'SELECT SQL_CACHE * FROM PUBLICACAO_SIMULADO_ALUNO WHERE PLS_ID = '.$this->pls_id.' AND ALU_ID = '.$this->data['ALU_ID'];
            $palu = $this->db->fetchRow($query);
            
            $query = 'SELECT SQL_CACHE p.*,d.DCP_NOM FROM PUBLICACAO_SIMULADO_GABARITO p, DISCIPLINA d '
                    .' WHERE p.DCP_ID = d.DCP_ID AND p.PLS_ID = '.$this->pls_id
                    .' AND p.PSG_STALNGETG = 1'
                    .' GROUP BY p.DCP_ID';
            $lngs = $this->db->fetchAll($query);
            $lngetg = true;
            if(count($lngs) >= 2){
                $lngetg = false;
                
                echo '<div style="padding-bottom: 10px;">';
                foreach($lngs as $lng){ 
                    $checked = $palu['DCP_ID'] == $lng['DCP_ID']  ? 'checked=""':''; 
                ?>
                <label><input type="radio" <?php echo $checked;?> class="lngetg" <?php echo $readonly; ?> name="lngetg" value="<?php echo $lng['DCP_ID']; ?>">
                    <?php echo $lng['DCP_NOM']; ?>
                </label> &nbsp; 
                <?php
                }
                echo '</div>';
                
                // teste para mostra ou não questões da lingua estrangeira selecionada
                if($palu['DCP_ID'] > 0) $lngetg = true; 
            }
            
            if($lngetg){
                
                echo '<input type="hidden" id="vallngetg" value="1">';
                
                // redação
                if($this->lista['PLS_REDID'] > 0){ ?>
                    <div style="padding-bottom: 10px;">
                        <strong>Redação:</strong> &nbsp; <input type="text" id="PSA_REDNTA" <?php echo $readonly; ?>  class="tam50 vnum" maxlength="5" value="<?php echo $palu['PSA_REDNTA']; ?>" />
                    </div>
                <?php }
                
                $query = 'SELECT SQL_CACHE * FROM PUBLICACAO_SIMULADO_GABARITO WHERE PLS_ID = '.$this->pls_id;
                $result = $this->db->fetchAll($query);
                foreach($result as $row){
                    
                    // teste para mostra ou não questão de lingua estrangeira selecionada
                    $lngetg_qst = true;
                    if($row['PSG_STALNGETG'] == 1){
                        if($palu['DCP_ID'] == $row['DCP_ID']) $lngetg_qst = true;
                        else $lngetg_qst = false;
                    } 
                    
                    if($lngetg_qst){
                    
                        $query = 'SELECT SQL_CACHE * FROM PUBLICACAO_SIMULADO_RESPOSTA '
                                .' WHERE PLS_ID = '.$row['PLS_ID']
                                .' AND ALU_ID = '.$this->data['ALU_ID']
                                .' AND PSR_QST = '.$row['PSG_QST']
                                .' AND DCP_ID = '.$row['DCP_ID'];
                        $resp = $this->db->fetchRow($query);

                        $num_qst = $row['PSG_QST'];

                        $html_row = '';

                        $html_row .= '<div class="cnt_el">';
                        $html_row .= '<span class="cnt_num_qst">';
                        $html_row .= '<input type="hidden" class="stalngetg" name="stalngetg['.$num_qst.']" value="'.$row['PSG_STALNGETG'].'">';
                        $html_row .= ' <input type="text" class="num_qst" name="q['.$num_qst.']" maxlength="3" value="'.$num_qst.'" readonly >';
                        $html_row .= ' <input type="hidden" class="plg" name="g['.$num_qst.']" value="'.$row['PSG_ID'].'" readonly >';
                        $html_row .= ' <input type="hidden" class="dcp" name="d['.$num_qst.']" value="'.$row['DCP_ID'].'" readonly >';

                        $html_row .= '</span>';

                        $html_row .= '<span class="cnt_qst_alt">';

                        if($resp['PSR_STA'] == 2){
                            $disabled = 'disabled="disabled"';
                            $readonly = 'readonly="readonly"';  
                        }else{
                            $disabled = '';
                            $readonly = '';
                        }

                        $arr_qst = dominio::getAlternativa($row['PSG_TPO']);

                        if(is_array($arr_qst)){
                            foreach($arr_qst as $key => $qst){
                                $checked = $key == $resp['PSR_ALT'] ? 'checked="checked"':'';
                                $class = $key == $resp['PSR_ALT'] ? 'btn_qst_alt_act':'';
                                $html_row .= '<input '.$disabled.' '.$checked.' type="radio" id="'.$num_qst.''.$key.'" class="rd_qst_alt" name="a['.$num_qst.']" value="'.$key.'" >';
                                $html_row .= ' &nbsp; <label for="'.$num_qst.''.$key.'"><span '.$disabled.' class="'.$class.' btn_qst_alt qst'.$num_qst.'" qst="'.$num_qst.'" val="'.$key.'">'.$qst.'</span></label> &nbsp; ';
                            }
                        } else if($row['PSG_TPO'] == 3){
                            $html_row .= '<input '.$readonly.' type="text" id="'.$num_qst.''.$key.'" class="num_int numero" maxlength="3" name="a['.$num_qst.']" value="'.$resp['PSR_ALT'].'" >';
                        }
                        $html_row .= '</span>';

                        //if($resp['PSR_STA'] == 2) $html_row .= '<span class="cnt_btn"><a href="javascript:void(0)" class="btn_cnf" qst="'.$num_qst.'" op="2">Alterar</a></span>';
                        //else $html_row .= '<span class="cnt_btn"><a href="javascript:void(0)" class="btn_cnf" qst="'.$num_qst.'" op="1">Confirmar</a></span>';

                        if($this->lista['PLS_STA'] == 2){
                            if($resp['PSR_ALT'] != $row['PSG_ALT']){
                                $html_row .= '<span class="cnt_alt_crt">Correta: <span class="alt">'.$row['PSG_ALT'].'</span></span>';
                            }else if($row['PSG_ALT']> ''){
                                $html_row .= '<span class="cnt_alt_crt"><img src="'.$this->urlbase.'/public/media/images/correct.png" /></span>';
                            }   
                        }

                        echo $html_row .= '</div>';  
                    
                    
                    }

                }
                
            } 
            ?>
        </div>
        
        <?php } else if($this->op == 'edit'){ ?>
        <table id="tlist">
            <thead>
                <tr>
                    <th>Disciplina</th>
                    <th>Porcentagem</th>
                    <th>Qtd. de Respostas</th>
                    <th>Qtd. de Acertos</th>
                    <th class="bc">&nbsp;</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach($this->result as $row){ ?>
                <tr>
                    <td><?php echo $row['DCP_NOM']; ?></td>
                    <td><?php echo $row['PQD_POR']; ?>%</td>
                    <td><?php echo $row['PQD_TOT']; ?></td>
                    <td><?php echo $row['PQD_ACR']; ?></td>
                </tr>
                <?php } ?>
            </tbody>
        </table>
        <?php }  ?>
        
        <div class="row cnt-frm-btn">
            <a href="<?php echo $this->urlmodulo.'/'.$this->controller.'/'.$this->action.'/id/'.$this->data['ALU_ID']; ?>" class="btn-frm">voltar</a>
        </div>
    </div>
</div>